package jee.boot.module.sms.config;

import jee.boot.module.sms.dao.SmsDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 初始化短信环境
 */
@Component
public class InitSms implements ApplicationRunner {
    /**
     * 日志对象
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SmsDao smsDao;
    @Value("${spring.schema}")
    private String schema;

    /**
     * 初始化邮件存储的表结构
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        {
            logger.info("短信服务初始化");
            int exist = smsDao.existTable(schema);
            if (exist > 0) {
                return;
            }else{
                logger.info("初始建表:"+schema+".st_sms");
                smsDao.createTable();
            }
        }
    }
}
